<script>
import axios from "axios";

export default {
  name: "UserUpdate",
  props:["id"],
  data(){
    return{
      form:{
        "id": 1,
        "name": "张三",
        "password": "123",
        "gender": "男",
        "birthday": "2000-02-02",
        "age": 24,
        "classInfo": {"id": 1, "name": "一年级"}
      },
      classInfoList:[]
    }
  },
  methods:{
    onSubmit(){
    },
    findById(id){
      axios.get(`http://localhost:8080/user2/${id}`)
          .then(result=>{
            this.form = result.data
          })
    },
    findClassInfo(){
      axios.get("http://localhost:8080/class/findAll")
          .then(result=>{
            this.classInfoList = result.data
      })
    }
  }
  ,watch:{
    id(newVal,oldVal){
      // console.log(oldVal,newVal)
      this.findById(newVal)
    }
  }
  ,mounted() {
    this.findById(this.id)
    this.findClassInfo()
  }
}
</script>

<template>
  <el-form :model="form" label-width="auto" style="max-width: 600px">
    <el-form-item label="编号">
      <el-input v-model="form.id" disabled />
    </el-form-item>
    <el-form-item label="姓名">
      <el-input v-model="form.name" />
    </el-form-item>
    <el-form-item label="密码">
      <el-input v-model="form.password" />
    </el-form-item>
    <el-form-item label="年级">
      <el-select v-model="form.classInfo.id" placeholder="请选择你的年级">
        <el-option v-for="item in classInfoList"  :value="item.id">{{item.name}}</el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="出生日期">
      <el-col :span="11">
        <el-date-picker
            v-model="form.birthday"
            type="date"
            placeholder="Pick a date"
            style="width: 100%"
        />
      </el-col>
    </el-form-item>
    <el-form-item label="年龄">
      <el-input v-model="form.age" />
    </el-form-item>
    <el-form-item label="性别">
      <el-radio-group v-model="form.gender">
        <el-radio value="男">男</el-radio>
        <el-radio value="女">女</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">Create</el-button>
      <el-button>Cancel</el-button>
    </el-form-item>
  </el-form>
</template>
<style scoped>
.el-form{
  margin: 20px;
}
</style>